package io.zcoder.innoway.models;

import android.os.Parcel;
import android.os.Parcelable;

import com.google.gson.annotations.SerializedName;

import io.zcoder.innoway.utils.Utils;

public class EntryTime implements Parcelable {
    @SerializedName("id")
    int id;
    @SerializedName("time")
    String time;
    @SerializedName("value")
    float value;
    int year;
    boolean checked;

    protected EntryTime(Parcel in) {
        id = in.readInt();
        time = in.readString();
        value = in.readFloat();
        year = in.readInt();
    }

    public static final Creator<EntryTime> CREATOR = new Creator<EntryTime>() {
        @Override
        public EntryTime createFromParcel(Parcel in) {
            return new EntryTime(in);
        }

        @Override
        public EntryTime[] newArray(int size) {
            return new EntryTime[size];
        }
    };

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public float getValue() {
        return value;
    }

    public float getValue(String unit) {
        int id = -1;
        switch (unit) {
            case "kg":
                id = 0;
                break;
            case "lbs":
                id = 1;
                break;
            case "st":
                id = 2;
                break;
            case "jin":
                id = 3;
                break;
        }
        if (id == -1) {
            return Utils.formatFloat(value);
        } else {
            return Utils.formatFloat(value * Utils.getRatioWeight(id));
        }
    }

    public String getValueWithUnit(String unit) {
        return getValue(unit) + unit;
    }

    public void setValue(float value) {
        this.value = value;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public boolean isChecked() {
        return checked;
    }

    public void setChecked(boolean checked) {
        this.checked = checked;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(id);
        dest.writeString(time);
        dest.writeFloat(value);
        dest.writeInt(year);
    }
}
